package com.financing.wap.web.filter;



import org.apache.log4j.Logger;

import com.financing.wap.weixin.pojo.AccessToken;
import com.financing.wap.weixin.pojo.Button;
import com.financing.wap.weixin.pojo.ComplexButton;
import com.financing.wap.weixin.pojo.Filter;
import com.financing.wap.weixin.pojo.Image;
import com.financing.wap.weixin.pojo.Media;
import com.financing.wap.weixin.pojo.Menu;
import com.financing.wap.weixin.pojo.ViewButton;
import com.financing.wap.weixin.util.WeixinUtil;

public class MenuManager {
	 //private static Logger log = LoggerFactory.getLogger(MenuManager.class);  
	
	
	//PRD
//   static String appId = "wx2be513b1530bc622";  
//   static String appSecret = "f531b39fe5a748302c485e3077a5a671"; 
//   
//	public static final String BASE_DOMAIN="dst.jindaozc.com";
	
	// 税筹测试
	   static String appId = "wxf6c72b9a5bf078f9";  
	   static String appSecret = "1260893cf3e7b3ff520cf78d24f7add7"; 
		public static final String BASE_DOMAIN="qmxjj.iask.in";
	
	//TEST
	//本地测试环境
//	static String appId = "wxa43920a2a7d39e1b";  
//	static String appSecret = "e98a3c6e9f22b2b15f02566d3f8e3cb4";  
//	public static final String BASE_DOMAIN="qmxjj.iask.in";

	static String v="%3fversion=4.1";
	
	public static final String baseAuthPath="http://"+BASE_DOMAIN+"/payraise/wxapi/weixin/wxAuth?redirect_url=";
	//访客数据  页面
	public static final  String visitPage=baseAuthPath+"http%3a%2f%2f"+BASE_DOMAIN+"%2fpage%2fvisitor.html"+v;
	//获客方式页面
	public static final  String articlePage=baseAuthPath+"http%3a%2f%2f"+BASE_DOMAIN+"%2fpage%2findex.html"+v;
	//设置名片页面
	public static final  String settingPage=baseAuthPath+"http%3a%2f%2f"+BASE_DOMAIN+"%2fpage%2fbCard.html"+v;
	//添加文章静态描述页面
	public static final  String noticeSetting=baseAuthPath+"http%3a%2f%2f"+BASE_DOMAIN+"%2fpage%2fnotice.html"+v;
	
	public static final  String pCenter=baseAuthPath+"http%3a%2f%2f"+BASE_DOMAIN+"%2fpage%2fpCenter.html"+v;
	//获客海报
	public static final  String posterPage=baseAuthPath+"http%3a%2f%2f"+BASE_DOMAIN+"%2fpage%2fposter.html"+v;
	
	//文章详情地址
	public static final  String articleDetailPage=baseAuthPath+"http%3a%2f%2f"+BASE_DOMAIN+"%2fpage%2fdetail.html%3fcode={0}%26userOpenid={1}";
	//个人中心地址
	
	public static final  String articleCreatePage="http://"+BASE_DOMAIN+"/page/create.html";
	//通知频率设置

	
	
	//我的任务
	public static final  String payraisePage=baseAuthPath+"http%3a%2f%2f"+BASE_DOMAIN+"%2fpage%2fmyRw.html"+v;
	
	static Logger log = Logger.getLogger(MenuManager.class);
	
	public static void main(String[] args) {
        // 调用接口获取access_token  
        AccessToken at = WeixinUtil.getAccessToken(appId, appSecret);  
        if (null != at) {  
            // 调用接口创建菜单  
            int result =WeixinUtil.createMenu(getMenushuichou(), at.getToken());  
  
            // 判断菜单创建结果  
            if (0 == result)  {
            	log.info("菜单创建成功！");
            }else{
            	 log.info("菜单创建失败，错误码：" + result);  
            }
                  
               
        } 
    
	}
	
    /** 
     * 组装菜单数据 
     *  
     * @return 
     */  
    private static Menu getMenushuichou() {  
    	
    	ViewButton btn11 = new ViewButton();  
    	btn11.setName("任务大厅");  
    	btn11.setType("view");  
    	btn11.setUrl(articlePage);
    	
    	ViewButton btn21 = new ViewButton();
		btn21.setName("个人中心");
		btn21.setType("view");
		btn21.setUrl(pCenter);
    	
        ViewButton btn31 = new ViewButton();  
        btn31.setName("我的任务");  
        btn31.setType("view");  
        btn31.setUrl(payraisePage);
        /** 
         * 这是公众号目前的菜单结构，每个一级菜单都有二级菜单项<br> 
         *  
         * 在某个一级菜单下没有二级菜单的情况，menu该如何定义呢？<br> 
         * 比如，第三个一级菜单项不是“更多体验”，而直接是“幽默笑话”，那么menu应该这样定义：<br> 
         * menu.setButton(new Button[] { mainBtn1, mainBtn2, btn33 }); 
         */  
        Menu menu = new Menu();  
        menu.setButton(new Button[] {btn11,btn31,btn21});  //mainBtn1, mainBtn2, mainBtn3
        return menu;  
    }  
	
	    /** 
	     * 组装菜单数据 
	     *  
	     * @return 
	     */  
	    private static Menu getMenu() {  
	    	
	    	ViewButton btn11 = new ViewButton();  
	    	btn11.setName("获客文章");  
	    	btn11.setType("view");  
	    	btn11.setUrl(articlePage);
	    	
	    	ViewButton btn12 = new ViewButton();  
	    	btn12.setName("获客海报");  
	    	btn12.setType("view");  
	    	btn12.setUrl(posterPage);
	    	
	    	 ComplexButton mainBtn1 = new ComplexButton();  
	        mainBtn1.setName("获客方式");  
	        mainBtn1.setSub_button(new Button[] { btn11, btn12 });  
	  
	        ViewButton btn21 = new ViewButton();  
	        btn21.setName("访问数据");  
	        btn21.setType("view");  
	        btn21.setUrl(visitPage);
	  
	        ViewButton btn31 = new ViewButton();  
	        btn31.setName("个人中心");  
	        btn31.setType("view");  
	        btn31.setUrl(pCenter);
	        /** 
	         * 这是公众号目前的菜单结构，每个一级菜单都有二级菜单项<br> 
	         *  
	         * 在某个一级菜单下没有二级菜单的情况，menu该如何定义呢？<br> 
	         * 比如，第三个一级菜单项不是“更多体验”，而直接是“幽默笑话”，那么menu应该这样定义：<br> 
	         * menu.setButton(new Button[] { mainBtn1, mainBtn2, btn33 }); 
	         */  
	        Menu menu = new Menu();  
	        menu.setButton(new Button[] {mainBtn1,btn21,btn31});  //mainBtn1, mainBtn2, mainBtn3
	        return menu;  
	    }  
	    /** 
	     * 组装菜单数据 
	     *  
	     * @return 
	     */  
	    private static Media getMedia() {  
	    	Filter filter = new Filter();
	    	filter.setGroup_id("0");
	    	Image image = new Image();
	    	image.setMedia_id("gkN91GaBBhKWIdcxe1wYLE8qFc1GvdeQSojN5y8wvWOGH4B3uHHtpVKzF6rMnWCH");
	    	Media media = new Media();
	    	media.setImage(image);
	    	media.setMsgtype("image");
	    	media.setFilter(filter);
			return media;  
	    }
	    

}
